package com.hnust.fiveonesix.Controller.ChangePwdController;
import com.hnust.fiveonesix.Mapper.LogiorRegiMapper.LoginMapper;
import com.hnust.fiveonesix.Mapper.LogiorRegiMapper.RegisterMapper;
import com.hnust.fiveonesix.POJO.RegisterInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class chanpwdController {
    @Autowired
    private RegisterMapper registerMapper;

    @Autowired
    private LoginMapper loginMapper;
    @RequestMapping("/CHANpwd")
    public String ChanPwd(@RequestParam("账号") String Id, @RequestParam("旧密码") String oldpwd,
                          @RequestParam("新密码") String newpwd, @RequestParam("二次新密码") String agapwd){
        RegisterInfo info = registerMapper.selectUserInfo(Id);
        if(info==null)
            return "forward:/修改密码/没有此账户.html";
        String userPwd = info.getUserPwd();
        if(!oldpwd.trim().equals(userPwd))
            return "forward:/修改密码/密码错误.html";
        if(!newpwd.trim().equals(agapwd))
            return "forward:/修改密码/密码不一致.html";
        loginMapper.charpwd(Id.trim(),newpwd.trim());
        registerMapper.Charpwd(Id.trim(),newpwd.trim());
        return "forward:/修改密码/修改成功.html";
    }
}
